package dgut.party.business.api.user;

import dgut.party.business.dto.vo.AccountVo;
import dgut.party.business.dto.vo.MenuTree;
import dgut.party.business.dto.vo.UserBriefVo;
import dgut.party.business.service.user.AccountRetrieveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/me")
public class UserApiController {

  @Autowired
  BCryptPasswordEncoder encrypter;

  @Autowired
  AccountRetrieveService accountRetrieveService;

  @PostMapping(path = "/brief", produces = "application/json;charset=UTF-8")
  public UserBriefVo myBriefInfo(Authentication auth) {
    return new UserBriefVo(accountRetrieveService.findByUsernameOrPhone(auth.getName()));
  }

  @RequestMapping("/detail")
  public AccountVo myAccountInfo(Authentication auth) {
    return new AccountVo(accountRetrieveService.findByUsernameOrPhone(auth.getName()));
  }

  @RequestMapping("/changepwd")
  public Object changeMypwd(@RequestBody Map<String,Object> requestParams, Authentication auth) {
//    (String)requestParams.get("old_password");
    return null;
  }

  @PostMapping(path = "/menus", produces = "application/json;charset=UTF-8")
  public MenuTree myMenus(Authentication auth) {
    return new MenuTree(accountRetrieveService.findAccountMenuTree(auth.getName()));
  }
}
